package com.example.creditscore;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;

public class Credit_score_form_sec_f extends Activity {
	
	/**
	 * @uml.property  name="btnNextPage"
	 * @uml.associationEnd  
	 */
	private Button BtnNextPage;
	/**
	 * @uml.property  name="datePickerBtnAppDate"
	 * @uml.associationEnd  
	 */
	private Button datePickerBtnAppDate;
	/**
	 * @uml.property  name="datePickerBtnAccOpen"
	 * @uml.associationEnd  
	 */
	private Button datePickerBtnAccOpen;
	/**
	 * @uml.property  name="mYear"
	 */
	private int mYear;
	/**
	 * @uml.property  name="mMonth"
	 */
	private int mMonth;
	/**
	 * @uml.property  name="mDay"
	 */
	private int mDay;
	/**
	 * @uml.property  name="minDate"
	 */
	private Calendar minDate;
	/**
	 * @uml.property  name="maxDate"
	 */
	private Calendar maxDate;
	/**
	 * @uml.property  name="tvDateAppDisplay"
	 * @uml.associationEnd  
	 */
	public TextView tvDateAppDisplay;
	/**
	 * @uml.property  name="tvDateAccOpenDisplay"
	 * @uml.associationEnd  
	 */
	public TextView tvDateAccOpenDisplay;
	/**
	 * @uml.property  name="btnBackPage"
	 * @uml.associationEnd  
	 */
	private Button btnBackPage;
	static final int DATE_DIALOG_ID = 0;
	static final int DATE_DIALOG_ID2 = 1;
	/**
	 * @uml.property  name="creditScoreFormF"
	 * @uml.associationEnd  readOnly="true"
	 */
	public Intent creditScoreFormF;
	/**
	 * @uml.property  name="x"
	 */
	private boolean x = true;
	
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.credit_score_form_sec_f);
		BtnNextPage = (Button) findViewById(R.id.nextPageBtn);
		datePickerBtnAppDate = (Button) findViewById(R.id.datePickerBtnAppDate);
		datePickerBtnAccOpen = (Button) findViewById(R.id.datePickerBtnOpenAcc);
		//BtnNextPage.setOnClickListener(nextPage());
		tvDateAppDisplay = (TextView) findViewById(R.id.tvDateAppDisplay);
		tvDateAccOpenDisplay = (TextView)  findViewById(R.id.tvDateAccOpenDisplay);
		btnBackPage = (Button) findViewById(R.id.backPageBtn);
		btnBackPage.setOnClickListener(backPage());
		datePickerBtnAppDate.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(DATE_DIALOG_ID);
				
				
			}
		});
		
		datePickerBtnAccOpen.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(DATE_DIALOG_ID2);
			}
		});
	}
	
	///For Date Application Given
	@Override 
	protected Dialog onCreateDialog(int id){
		switch(id) {
		case DATE_DIALOG_ID:
			return new DatePickerDialog(this,mDateSetListener, mYear, mMonth,mDay);
		
		case DATE_DIALOG_ID2:
			
			return new DatePickerDialog(this,mDateSetListener2, mYear, mMonth,mDay);
		}
		return null;
	}
	
	 
	
     
	//the callback receive when the user "sets" the date in the dialog
	/**
	 * @uml.property  name="mDateSetListener"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private DatePickerDialog.OnDateSetListener
	mDateSetListener = new DatePickerDialog.OnDateSetListener() {
		 
		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			
			//get the current date
			final Calendar c = Calendar.getInstance();
			mYear = year;
			mMonth = monthOfYear;
			mDay = dayOfMonth;
			
			
			      
			
			updateDisplay();
			
		}
	};
	
	//updates the dates in the textView
	private void updateDisplay(){
		tvDateAppDisplay.setText(new StringBuilder()
				//month is 0 base so add 1
				.append(mMonth + 1).append("-")
				.append(mDay).append("-")
				.append(mYear).append(" "));
	}
	
	
	//For Date account open
	
	
	
	//the callback receive when the user "sets" the date in the dialog
	/**
	 * @uml.property  name="mDateSetListener2"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private DatePickerDialog.OnDateSetListener
	 mDateSetListener2 = new DatePickerDialog.OnDateSetListener() {
		 
		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			
			//get the current date
			final Calendar c = Calendar.getInstance();
			mYear = year;
			mMonth = monthOfYear;
			mDay = dayOfMonth;
			updateDisplay2();
			
		}
	};
	
	//updates the dates in the textView
	private void updateDisplay2(){
		tvDateAccOpenDisplay.setText(new StringBuilder()
				//month is 0 base so add 1
				.append(mMonth + 1).append("-")
				.append(mDay).append("-")
				.append(mYear).append(" "));
	}
	
	
	
	
	
	/*Next PAge method
	private OnClickListener nextPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(context,
						DisplayDeclaration.class);
				startActivity(intent);

			}
		};
	
	}*/
	
	private OnClickListener backPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {

				Intent intent = new Intent(context,
						Credit_score_form_sec_e.class);
				startActivity(intent);

			}
		};
	}
	

	


	


}
